package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {

    @Autowired
    private ItemMapper itemMapper;


    /**
     * 根据Id删除商品  service
     * @param id
     */
    @Override
    public void deleteItem(Long id) {
        //上架的商品不能删除
        Item item = itemMapper.selectById(id);
        if (item.getStatus() == 1) {

            throw new RuntimeException("上架的商品不能删除,请先下架");

        }

        itemMapper.deleteById(id);
        log.info("删除商品成功");


    }


}
